package com.bicon.botu.mall.component.api;

import com.bicon.botu.mall.component.service.IComponentBrowsingHistoryService;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



/**
 * @Author 李双喜
 * @Date 2017/8/3 12:43
 */
@RestController
@RequestMapping("/V1.0.0/api/browsingHistory")
public class ComponentBrowsingHistoryApi extends BaseController{
    @Autowired
    private IComponentBrowsingHistoryService iComponentBrowsingHistoryService;

    /**
     * 添加浏览记录
     * @param historyJson 历史记录json
     * @return            BaseResult
     */
    @RequestMapping(value = "/addHistory", method = RequestMethod.POST)
    public BaseResult addHistory(@RequestParam("type") String type, @RequestParam("historyJson") String historyJson) {
        if(iComponentBrowsingHistoryService.insertHistory(getUserId(), type, historyJson)){
            return sendResult200();
        }
        return sendResult500();
    }

    /**
     * 批量删除
     * @param browsingHistoryIdJson   多个浏览历史id
     * @return                        BaseResult
     */
    @RequestMapping(value = "/deleteHistory", method = RequestMethod.POST)
    public BaseResult deleteHistory(@RequestParam("browsingHistoryIdJson") String browsingHistoryIdJson,@RequestParam("type") String type) {
        return iComponentBrowsingHistoryService.deleteHistory(browsingHistoryIdJson, type, getUserId());
    }

    /**
     * 清空所有
     * @param type   类型
     * @return       BaseResult
     */
     @RequestMapping(value = "/deleteAllHistory",method = RequestMethod.POST)
     public BaseResult deleteAllBrowsingHistory(@RequestParam("type") String type){
       return iComponentBrowsingHistoryService.deleteAll(getUserId(),type);
     }

    /**
     * 查询浏览历史
     * @param type     类型
     * @return         BaseResult
     */
    @RequestMapping(value = "/getBrowsingHistory",method = RequestMethod.POST)
    public BaseResult getBrowsingHistory(@RequestParam("type") String type){
        return iComponentBrowsingHistoryService.getBrowsingHistory(getUserId(),type);
    }
}
